home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Games / WHDLoad / Src / imager-examples / arkanoid.imager.asm next >
Encoding:
Assembly Source File  |  2000-05-16  |  10.9 KB  |  549 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    arkanoid.imager.asm
  3. ;  :Contents.    Imager for Arkanoid
  4. ;  :Author.    Wepl
  5. ;  :Version.    $Id: arkanoid.imager.asm 1.3 1999/05/17 23:14:46 jah Exp $
  6. ;  :History.    26.07.98 started
  7. ;        24.11.98 insert disk fixed, index flag removed
  8. ;        17.05.99 file size for "Arkanoid.2" incremented for PAL-version
  9. ;  :Requires.    -
  10. ;  :Copyright.    Public Domain
  11. ;  :Language.    68000 Assembler
  12. ;  :Translator.    Barfly V2.9
  13. ;  :To Do.
  14. ;---------------------------------------------------------------------------*
  15. ;
  16. ;    Disk format:
  17. ;    Disk 1:        0-1    standard
  18. ;            2-61    $1a20 bytes sync=9521,...
  19. ;            62-159    unused
  20. ;
  21. ;    Image format:
  22. ;    Disk 1        2-10    Arkanoid.1
  23. ;            12-41    Arkanoid.2
  24. ;            50-61    Arkanoid.3
  25. ;
  26. ;---------------------------------------------------------------------------*
  27.  
  28.     INCDIR    Includes:
  29.     INCLUDE    devices/trackdisk.i
  30.     INCLUDE    dos/dos.i
  31.     INCLUDE    intuition/intuition.i
  32.     INCLUDE    lvo/dos.i
  33.     INCLUDE    lvo/exec.i
  34.     INCLUDE    lvo/intuition.i
  35.     INCLUDE    patcher.i
  36.  
  37.     IFD BARFLY
  38.     OUTPUT    "C:Parameter/arkanoid.imager"
  39.     BOPT    O+ OG+            ;enable optimizing
  40.     BOPT    ODd- ODe-        ;disable mul optimizing
  41.     ENDC
  42.  
  43. ;======================================================================
  44.  
  45.     SECTION a,CODE
  46.  
  47.         moveq    #-1,d0
  48.         rts
  49.         dc.l    _Table
  50.         dc.l    "PTCH"
  51.  
  52. ;======================================================================
  53.  
  54. _Table        dc.l    PCH_ADAPTOR,.adname        ;name adaptor
  55.         dc.l    PCH_NAME,.name            ;description of parameter
  56.         dc.l    PCH_FILECOUNT,3            ;number of cycles
  57.         dc.l    PCH_FILENAME,.filenamearray    ;file names
  58.         dc.l    PCH_DATALENGTH,_lengtharray    ;file lengths
  59.         dc.l    PCH_DISKNAME,.disknamearray    ;disk names
  60.         dc.l    PCH_SPECIAL,.specialarray    ;functions
  61.         dc.l    PCH_STATE,.statearray        ;state texts
  62.         dc.l    PCH_MINVERSION,.patcherver    ;minimum patcher version required
  63.         dc.l    PCH_INIT,_Init            ;init routine
  64.         dc.l    PCH_FINISH,_Finish        ;finish routine
  65.         dc.l    PCH_ERRORINPARAMETER,_Finish    ;finish routine
  66.         dc.l    TAG_DONE
  67.  
  68. .filenamearray    dc.l    .f1
  69.         dc.l    .f2
  70.         dc.l    .f3
  71. .disknamearray    dc.l    .d
  72.         dc.l    .d
  73.         dc.l    .d
  74. .specialarray    dc.l    _Special
  75.         dc.l    _Special
  76.         dc.l    _Special
  77. .statearray    dc.l    .insertdisk
  78.         dc.l    .insertdisk
  79.         dc.l    .insertdisk
  80.  
  81. .f1        dc.b    "Arkanoid.1",0
  82. .f2        dc.b    "Arkanoid.2",0
  83. .f3        dc.b    "Arkanoid.3",0
  84. .d        dc.b    "ArkanoidI",0
  85.  
  86. .adname        dc.b    "Done by Wepl.",0
  87. .name        dc.b    "Arkanoid, Diskimager for HD-Install",0
  88. .patcherver    dc.b    "V1.05"
  89. .insertdisk    dc.b    'Please insert your original writepro-',10
  90.         dc.b    'tected disk in the source drive.',0
  91.     IFD BARFLY
  92.         dc.b    "$VER: "
  93.     DOSCMD    "WDate >T:date"
  94.     INCBIN    "T:date"
  95.         dc.b    0
  96.     ENDC
  97.     EVEN
  98.  
  99. ;======================================================================
  100.  
  101. _Init        moveq    #0,d0                ;source drive
  102.         move.l    PTB_INHIBITDRIVE(a5),a0        ;inhibit drive
  103.         jsr    (a0)
  104.         tst.l    d0
  105.         bne    .error
  106.         
  107.         moveq    #0,d0                ;source drive
  108.         move.l    PTB_OPENDEVICE(a5),a0        ;open source device
  109.         jsr    (a0)
  110.         tst.l    d0
  111.         bne    .error
  112.         rts
  113.  
  114. .error        bsr    _Finish
  115.         moveq    #-1,d0
  116.         rts
  117.  
  118. ;======================================================================
  119.  
  120. _Finish        moveq    #0,d0                ;source drive
  121.         move.l    PTB_ENABLEDRIVE(a5),a0        ;deinhibit drive
  122.         jmp    (a0)
  123.  
  124. ;======================================================================
  125.  
  126. RAWREADLEN    = $7c00
  127. BYTESPERTRACK    = $1a20
  128.  
  129. ;======================================================================
  130.  
  131. _lengtharray    dc.l    53760
  132.         dc.l    194432+$6c
  133.         dc.l    80120
  134. _starttrack    dc.b    2
  135.         dc.b    12
  136.         dc.b    50
  137. _counttrack    dc.b    9
  138.         dc.b    30
  139.         dc.b    12
  140.  
  141. _sync        dc.w    0
  142. _nexttrack    dc.w    0
  143.  
  144. ;======================================================================
  145.  
  146. _Special    moveq    #-1,d7                ;D7 = return code (default=error)
  147.  
  148.         cmp.w    #0,d6                ;first cycle ?
  149.         bne    .notfirst
  150.  
  151. .idisk        bsr    _InsertDisk
  152.         tst.l    d0
  153.         beq    .nodisk
  154.         
  155.     ;check for disk in drive
  156.         move.l    (PTB_DEVICESOURCEPTR,a5),a1
  157.         move.w    #TD_CHANGESTATE,(IO_COMMAND,a1)
  158.         move.l    (4).w,a6
  159.         jsr    (_LVODoIO,a6)
  160.         tst.l    (IO_ACTUAL,a1)
  161.         bne    .idisk
  162. .notfirst
  163.         move.w    #$9521,(_sync)            ;initial sync for each file
  164.  
  165.         moveq    #0,d2                ;D2 = start/actual track
  166.         move.b    (_starttrack,pc,d6.w),d2
  167.         moveq    #0,d3                ;D3 = amount of tracks
  168.         move.b    (_counttrack,pc,d6.w),d3
  169.         move.l    (PTB_ADDRESSOFFILE,a5),a2    ;A2 = file address
  170.  
  171. .next        move.l    d2,d0
  172.         move.l    d3,d1
  173.         bsr    _Display
  174.     IFEQ 0
  175.         moveq    #5-1,d4                ;D4 = retries decoding
  176. .decretry    moveq    #5-1,d5                ;D5 = retries rawread
  177. .tdretry    move.l    (PTB_DEVICESOURCEPTR,a5),a1
  178.         move.l    (PTB_SPACE,a5),(IO_DATA,a1)    ;track is to load in ptb_space
  179.         move.l    #RAWREADLEN,(IO_LENGTH,a1)    ;double length of track to decode the index-sync-read data
  180.         move.l    d2,(IO_OFFSET,a1)
  181.         move.w    #TD_RAWREAD,(IO_COMMAND,a1)
  182.         move.b    #0,(IO_FLAGS,a1)
  183.         move.l    (4).w,a6
  184.         jsr    (_LVODoIO,a6)
  185.         tst.l    d0
  186.         beq    .tdok
  187.         dbf    d5,.tdretry
  188.         bra    .tderr
  189.     ELSE
  190.     IFEQ 1
  191.         movem.l    d2-d4/a2-a3,-(a7)
  192.         lea    (.name),a0            ;format string
  193.         move.w    d2,d0
  194.         lsr.w    #1,d0
  195.         and.w    #1,d2
  196.         movem.w    d0/d2,-(a7)
  197.         move.l    a7,a1                ;arg array
  198.         lea    (_PutChar),a2
  199.         sub.l    #100-4,a7
  200.         move.l    a7,a3                ;buffer
  201.         move.l    (4),a6
  202.         jsr    (_LVORawDoFmt,a6)
  203.         move.l    a7,d1
  204.         move.l    #MODE_OLDFILE,d2
  205.         move.l    (PTB_DOSBASE,a5),a6
  206.         jsr    (_LVOOpen,a6)
  207.         add.l    #100,a7
  208.         move.l    d0,d4
  209.         beq    .err
  210.         move.l    d4,d1
  211.         move.l    (PTB_SPACE,a5),d2
  212.         addq.l    #2,d2                ;because decoder will not read first word
  213.         move.l    #RAWREADLEN-2,d3
  214.         jsr    (_LVORead,a6)
  215.         move.l    d4,d1
  216.         jsr    (_LVOClose,a6)
  217.         moveq    #-1,d0
  218. .err        movem.l    (a7)+,d2-d4/a2-a3
  219.         tst.l    d0
  220.         beq    .tderr
  221.         moveq    #0,d4                ;no retries
  222.         bra    .tdok
  223. .name        dc.b    "ram:track_%02d_head_%02d",0,0
  224.     ELSE
  225.         movem.l    d2-d6,-(a7)
  226.         move.l    d2,d6
  227.         moveq    #0,d5
  228.         sub.w    #168*4,a7
  229.         lea    .name,a0
  230.         move.l    a0,d1
  231.         move.l    #MODE_OLDFILE,d2
  232.         move.l    (PTB_DOSBASE,a5),a6
  233.         jsr    (_LVOOpen,a6)
  234.         move.l    d0,d4
  235.         beq    .err
  236.         move.l    d4,d1
  237.         move.l    #16,d2
  238.         move.l    #OFFSET_BEGINNING,d3
  239.         jsr    (_LVOSeek,a6)            ;skip header
  240.         move.l    d4,d1
  241.         move.l    a7,d2
  242.         move.l    #168*4,d3
  243.         jsr    (_LVORead,a6)
  244.         cmp.l    d0,d3
  245.         bne    .close
  246.         moveq    #0,d0
  247.         moveq    #0,d1
  248.         moveq    #0,d2
  249. .0        cmp.w    d0,d6
  250.         beq    .1
  251.         move.l    (a7,d1.l),d3
  252.         and.l    #$ffff,d3
  253.         beq    .2
  254.         add.l    d3,d2
  255.         add.l    #16,d2                ;skip track headline
  256. .2        addq.l    #1,d0
  257.         addq.l    #4,d1
  258.         bra    .0
  259. .1        move.l    d4,d1
  260.         add.l    #16,d2                ;skip track headline
  261.         move.l    #OFFSET_CURRENT,d3
  262.         jsr    (_LVOSeek,a6)
  263.         move.l    d4,d1
  264.         move.l    (PTB_SPACE,a5),d2
  265.         move.l    #RAWREADLEN,d3
  266.         jsr    (_LVORead,a6)
  267.         cmp.l    d0,d3
  268.         bne    .close
  269.         moveq    #-1,d5
  270. .close        move.l    d4,d1
  271.         jsr    (_LVOClose,a6)
  272. .err        add.w    #168*4,a7
  273.         move.l    d5,d0
  274.         movem.l    (a7)+,d2-d6
  275.         tst.l    d0
  276.         beq    .tderr
  277.         moveq    #0,d4                ;no retries
  278.         bra    .tdok
  279. .name        dc.b    "develop:cracks/arkanoid/ark.wwp",0
  280.     ENDC
  281. .decretry
  282.     ENDC
  283. .tdok
  284.         move.l    (PTB_SPACE,a5),a0        ;source
  285.         move.l    a2,a1                ;destination
  286.         bsr    _Decode
  287.         tst.l    d0
  288.         beq    .decok
  289.         dbf    d4,.decretry
  290.         bra    .decerr
  291. .decok
  292.         add.l    #BYTESPERTRACK,a2
  293.         move.w    (_nexttrack),d2            ;one tracks further
  294.         subq.w    #1,d3                ;one track less
  295.         bne    .next
  296.  
  297.         moveq    #0,d7                ;return code
  298.         cmp.w    #2,d6                ;last cycle ?
  299.         bne    .quit
  300.         bra    .motoff
  301. .decerr
  302. .tderr        bsr    _ReadError
  303.  
  304.     ;switch motor off
  305. .motoff        move.l    (PTB_DEVICESOURCEPTR,a5),a1
  306.         clr.l    (IO_LENGTH,a1)
  307.         move.w    #TD_MOTOR,(IO_COMMAND,a1)
  308.         move.l    (4).w,a6
  309.         jsr    (_LVODoIO,a6)
  310. .nodisk
  311.     ;enable drive
  312.         tst.b    d7
  313.         beq    .quit
  314.         bsr    _Finish
  315.         
  316. .quit        move.l    d7,d0
  317.         rts
  318.  
  319. ;======================================================================
  320. ; IN:    A0 = raw
  321. ;    A1 = dest
  322. ; OUT:    D0 = error
  323.  
  324. GetW    MACRO
  325.         cmp.l    a0,a5
  326.         bls    .error
  327.         move.l    (a0),\1
  328.         lsr.l    d5,\1
  329.     ENDM
  330. GetW2    MACRO
  331.         cmp.l    a2,a5
  332.         bls    .error
  333.         move.l    (a2),\1
  334.         lsr.l    d5,\1
  335.     ENDM
  336. GetWI    MACRO
  337.         GetW    \1
  338.         addq.l    #2,a0
  339.     ENDM
  340. GetWI2    MACRO
  341.         GetW2    \1
  342.         addq.l    #2,a2
  343.     ENDM
  344. GetLI    MACRO
  345.         GetWI    \1
  346.         swap    \1
  347.         GetWI    \2
  348.         move.w    \2,\1
  349.     ENDM
  350. GetLI2    MACRO
  351.         GetWI2    \1
  352.         swap    \1
  353.         GetWI2    \2
  354.         move.w    \2,\1
  355.     ENDM
  356. GetL2    MACRO
  357.         GetWI2    \1
  358.         swap    \1
  359.         GetW2    \2
  360.         move.w    \2,\1
  361.         subq.l    #2,a2
  362.     ENDM
  363.  
  364. _Decode        movem.l    d1-a6,-(a7)
  365.         move.l    a7,a6            ;A6 = return stack
  366.         lea    (RAWREADLEN,a0),a5    ;A5 = end of raw data
  367.  
  368.     ;find sync
  369. .sync1        moveq    #16-1,d5        ;D5 = shift count
  370. .sync2        GetW    d0
  371.         cmp.w    (_sync),d0
  372.         beq    .sync3
  373. .sync_retry    dbf    d5,.sync2
  374.         addq.l    #2,a0
  375.         bra    .sync1
  376.  
  377. .sync3        move.l    a0,-(a7)        ;save this point for new try
  378.  
  379.         addq.l    #2,a0            ;skip sync
  380.         
  381.         lea    (_buffer),a3
  382.  
  383.         MOVEQ    #1,D0            ;size
  384.     ;    MOVEQ    #0,D1            ;offset
  385.         BSR.B    .sub
  386.         MOVEQ    #1,D0
  387.     ;    MOVEQ    #2,D1
  388.         BSR.B    .sub
  389.         MOVEQ    #1,D0
  390.     ;    MOVEQ    #4,D1
  391.         BSR.B    .sub
  392.         MOVEQ    #1,D0
  393.     ;    MOVEQ    #6,D1
  394.         BSR.B    .sub
  395.         MOVE.L    #$D10,D0
  396.     ;    MOVEQ    #8,D1
  397.         BSR.B    .sub
  398.         MOVEQ    #1,D0
  399.     ;    MOVE.L    #$1A28,D1
  400.         BSR.B    .sub
  401.         MOVEQ    #1,D0
  402.     ;    MOVE.L    #$1A2A,D1
  403.         BSR.B    .sub
  404.  
  405.         lea    (_buffer),a3
  406.         move.l    a3,a2
  407.         CLR.W    D0
  408.         MOVE.W    #$D14,D2
  409. .1        MOVE.W    (A2)+,D1
  410.         EOR.W    D1,D0
  411.         ROR.W    #1,D0
  412.         DBRA    D2,.1
  413.         cmp.w    (_buffer+$1a2a),d0
  414.         bne    .fail
  415.  
  416.         lea    (8,a3),a0
  417.         move.w    (6,a3),d0
  418.         subq.w    #1,d0
  419. .2        move.b    (a0)+,(a1)+
  420.         dbf    d0,.2
  421.  
  422.         move.w    (a3)+,d0
  423.         beq    .3
  424.         move.w    d0,(_sync)
  425. .3        move.w    (a3),(_nexttrack)
  426.  
  427.         bra    .success
  428.  
  429. .fail        move.l    (a7)+,a0
  430.         bra    .sync_retry        ;try again
  431.  
  432. .success    moveq    #0,d0
  433. .quit        move.l    a6,a7
  434.         movem.l    (a7)+,d1-a6
  435.         rts
  436. .error
  437.     IFEQ 1
  438.         lea    .snc,a0
  439.         move.w    _sync,d0
  440. .s1        cmp.w    (a0)+,d0
  441.         bne    .s1
  442.         move.w    (a0),(_sync)
  443.         beq    .s2
  444.         move.l    a6,a7
  445.         movem.l    (a7)+,d1-a6
  446.         bra    _Decode
  447. .snc        dc.w    $9521,$5259,$2559,$2145,$2541,$4252,$4489,$448A,$5241,$5412,$A424,$A425,$A429,$A484,0
  448. .s2
  449.     ENDC
  450.         moveq    #-1,d0
  451.         bra    .quit
  452.  
  453.  
  454. .sub        MOVEA.L    A0,A2
  455.         ADDA.L    D0,A2
  456.         ADDA.L    D0,A2
  457.         MOVE.W    #$AAAA,D3
  458.         MOVE.W    #$5555,D4
  459.         SUBQ.L    #1,D0
  460. .5        GetWI    d1            ;MOVE.W    (A0)+,D1
  461.         ADD.W    D1,D1
  462.         AND.W    D3,D1
  463.         GetWI2    d2            ;MOVE.W    (A2)+,D2
  464.         AND.W    D4,D2
  465.         OR.W    D1,D2
  466.         MOVE.W    D2,(A3)+
  467.         DBRA    D0,.5
  468.         move.l    a2,a0
  469.         rts
  470.  
  471. ;======================================================================
  472.  
  473. _InsertDisk    sub.l    a0,a0                ;window
  474.         pea    (.gadgets)
  475.         pea    (.text)
  476.         pea    (.titel)
  477.         clr.l    -(a7)
  478.         pea    (EasyStruct_SIZEOF)
  479.         move.l    a7,a1                ;easyStruct
  480.         sub.l    a2,a2                ;IDCMP_ptr
  481.         move.l    d6,-(a7)
  482.         addq.l    #1,(a7)
  483.         move.l    a7,a3                ;Args
  484.         move.l    (PTB_INTUITIONBASE,a5),a6
  485.         jsr    (_LVOEasyRequestArgs,a6)
  486.         add.w    #6*4,a7
  487.         rts
  488.  
  489. .titel        dc.b    "Insert Disk",0
  490. .text        dc.b    "Insert your orginal disk %ld",10
  491.         dc.b    "into the source drive !",0
  492. .gadgets    dc.b    "OK|Cancel",0,0
  493.  
  494. ;======================================================================
  495.  
  496. _ReadError    sub.l    a0,a0                ;window
  497.         pea    (.gadgets)
  498.         pea    (.text)
  499.         pea    (.titel)
  500.         clr.l    -(a7)
  501.         pea    (EasyStruct_SIZEOF)
  502.         move.l    a7,a1                ;easyStruct
  503.         sub.l    a2,a2                ;IDCMP_ptr
  504.         move.l    d2,-(a7)
  505.         move.l    a7,a3                ;Args
  506.         move.l    (PTB_INTUITIONBASE,a5),a6
  507.         jsr    (_LVOEasyRequestArgs,a6)
  508.         add.w    #6*4,a7
  509.         rts
  510.  
  511. .titel        dc.b    "Error",0
  512. .text        dc.b    "Can't read track %ld",0
  513. .gadgets    dc.b    "OK",0
  514.  
  515. ;======================================================================
  516. ; IN:    D0 = actual tracknumber
  517. ;    D1 = tracks left to do
  518.  
  519. _Display    movem.l    d0-d1/a0-a3/a6,-(a7)
  520.         lea    (.text),a0        ;format string
  521.         move.l    d1,-(a7)
  522.         move.l    d0,-(a7)
  523.         move.l    a7,a1            ;arg array
  524.         lea    (_PutChar),a2
  525.         sub.l    #100-8,a7
  526.         move.l    a7,a3            ;buffer
  527.         move.l    (4),a6
  528.         jsr    (_LVORawDoFmt,a6)
  529.         move.l    a7,a0
  530.         move.l    (PTB_DISPLAY,a5),a6
  531.         jsr    (a6)
  532.         add.l    #100,a7
  533.         movem.l    (a7)+,d0-d1/a0-a3/a6
  534.         rts
  535.  
  536. .text        dc.b    "reading track %ld, left %ld",0
  537.  
  538. _PutChar    move.b    d0,(a3)+
  539.         rts
  540.  
  541. ;======================================================================
  542.  
  543.     SECTION b,BSS
  544.  
  545. _buffer        dsb    $1a2c
  546.  
  547.     END
  548.  
  549.